﻿using HCMS.CommonDtos;
using HCMS.Entities.Base;
using HCMS.IRepositories.Base;
using HCMS.IServices.Base;
using HCMS.Repositories.Base;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace HCMS.Services.Base
{
    /// <summary>
    /// 网站前端监控 - 异常日志 应用服务
    /// </summary>
    public class FrontEndErrorLogsAppService : CommonAppService<BaseDbContext, FrontEndErrorLogs>, IFrontEndErrorLogsAppService
    {
        private readonly IRepository<FrontEndErrorLogs> baseFrontEndErrorLogsRepository;
        private readonly IFrontEndErrorLogsRepository frontEndErrorLogsRepository;

        public FrontEndErrorLogsAppService(
            IRepository<FrontEndErrorLogs> baseFrontEndErrorLogsRepository,
            IFrontEndErrorLogsRepository frontEndErrorLogsRepository
            ) : base(baseFrontEndErrorLogsRepository)
        {
            this.baseFrontEndErrorLogsRepository = baseFrontEndErrorLogsRepository;
            this.frontEndErrorLogsRepository = frontEndErrorLogsRepository;
        }

        /// <summary>
        /// 管理 列表
        /// </summary>
        /// <param name="searchArgs">搜索 参数</param>
        /// <param name="pager">分页 参数</param>
        /// <returns></returns>
        public async Task<ListPagerDto<object>> ManageList(SearchArgsDto searchArgs, PagerArgsDto pager)
        {
            var frontEndErrorLogs = await frontEndErrorLogsRepository.ManageList(searchArgs, pager);

            var result = new ListPagerDto<object>();
            result.PagerInfo = frontEndErrorLogs.PagerInfo;

            var data = new List<object>();
            foreach (var item in frontEndErrorLogs.Data)
            {
                data.Add(new
                {
                    id = item.Id,
                    createTime = item.CreateTime,
                    appId = item.AppId,
                    url = item.Url,
                    clientSystem = item.ClientSystem,
                    networkType = item.NetworkType,
                    errorMessage = item.ErrorMessage,
                    lineNo = item.LineNo,
                    columnNo = item.ColumnNo,
                });
            }

            result.Data = data;

            return result;
        }
    }
}
